package org.jash.shop2202.entity

import android.animation.Animator
import android.animation.Animator.AnimatorListener
import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.alibaba.android.arouter.launcher.ARouter
import org.jash.shop2202.goods.DetailActivity

@Entity
data class Goods(
    val category_id: Int,
    val goods_attribute: String,
    val goods_banner: String,
    val goods_code: String,
    val goods_default_icon: String,
    val goods_default_price: Float,
    val goods_desc: String,
    val goods_detail_one: String,
    val goods_detail_two: String,
    val goods_sales_count: Int,
    val goods_stock_count: Int,
    @PrimaryKey
    val id: Int
) {
    @Ignore
    val bannerList: List<String> = listOf()
    fun showDetail(context:Context) {
        ARouter.getInstance().build("/shop/detail")
            .withInt("id", id)
            .navigation()

    }
    fun animate(view:View) {
        view.animate()
            .setDuration(1000)
            .rotation(360f)
            .scaleY(1.2f)
            .scaleX(1.2f)
            .setListener(object :AnimatorListener {
                override fun onAnimationStart(animation: Animator) {
                }

                override fun onAnimationEnd(animation: Animator) {
                    view.rotation = 0f
                    view.scaleX = 1f
                    view.scaleY = 1f
                }

                override fun onAnimationCancel(animation: Animator) {
                    view.rotation = 0f
                    view.scaleX = 1f
                    view.scaleY = 1f
                }

                override fun onAnimationRepeat(animation: Animator) {
                }
            }).start()
    }
}